import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Stack;

public class MyStack {
    private int[] elem;
    private int usedSize;

    private static final int DEFAULT_CAPACITY = 4;

    public MyStack(){
        this.elem = new int[DEFAULT_CAPACITY];
    }







    public void push(int val){
        if (isFull()){
            elem = Arrays.copyOf(elem,usedSize*2);
        }
        elem[usedSize] = val;
        usedSize++;
    }

    public boolean isFull(){
        return usedSize==elem.length;
    }

    public int pop(){
        if (isEmpty()){
            throw new Empty();
        }
        usedSize--;
        return elem[usedSize];
    }

    public int peek(){
        if (isEmpty()){
            throw new Empty();
        }
        return elem[usedSize-1];
    }

    public boolean isEmpty(){
        return usedSize==0;
    }

}
